//
//  ZHStatusViewModel.swift
//  ZHWeibo
//
//  Created by user on 15/12/9.
//  Copyright © 2015年 heima. All rights reserved.
//

import UIKit

class ZHStatusViewModel: NSObject {
    //拥有模型属性
    var statusModel: [ZHStatusUserViewModel]?
    
    
}


extension ZHStatusViewModel{
    //提供加载数据的方法,给控制器使用
    func loadHomeData(complete: ((isSuccess: Bool) -> ())){
        ZHHttpDownLoadTools.shareInstance.getFrendsWeiInfo(ZHUserAccountViewModel.shareAccountInstance.accessToken!) { (response, error) -> () in
            if error != nil {
                complete(isSuccess: false)
                return
            }
            //判断获取的盆友微博数据是不是字典
            guard let dict = response as? [String: AnyObject] else{
                complete(isSuccess: false)
                return
            }
            //判断每一条数据是不是一个字典
            guard let dataDict = dict["statuses"] as? [[String: AnyObject]] else {
                complete(isSuccess: false)
                return
            }
            //获取每一条微博的数据,并放入数组----字典转模型
            var tempArray = [ZHStatusUserViewModel]()
            for item in dataDict {
               
                let status = ZHStatusModel(dict: item)
                tempArray.append(ZHStatusUserViewModel(statusModel: status))
            }
            self.statusModel = tempArray
            complete(isSuccess: true)
        }
    }
}














